<template>
  <div class="preface-box">
    <div class="preface-content">
      <div class="preface-right" ref="prefaceLeft">
        <t-image
          class="preface-right-img"
          :src="$filters.getLinkUrl(props.info.value + '?imageView2/1/w/380/h/710/format/webp')"
          alt=""
          v-if="props.info.value"
        />
        <!-- <t-image
          class="preface-right-img"
          src="http://101.34.143.36:8890/api/image/387939155165253/h_710,w_380"
          alt=""
          v-else
        /> -->
        <UnitImageNull v-else></UnitImageNull>
      </div>
      <div class="preface-left" ref="prefaceRight">
        <titles :title="props.info.text" />
        <div class="subTitle" v-if="props.info.subTitle">——{{ props.info.subTitle }}</div>
        <span
          class="left-title hw-wrap-spases"
          :style="{
            fontSize: store.styleInfo.contentSize,
            fontFamily: store.styleInfo.textFamily,
            color: store.styleInfo.fontColor,
          }"
          >{{ props.info.remarks }}</span
        >
        <div
          @click="clickPath"
          :style="{
            fontFamily: 'SourceHanSerifCN-Bold',
            fontSize: '14px',
            color: '#fff',
          }"
          class="left-btn flex-c-c-c"
        >
          <div class="btn-img">
            <buttonIcon />
          </div>
          <span>查看全部</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
// @ts-nocheck
import { pathList, pathListLoop } from '../route';
import { ref, onMounted } from 'vue';
import titles from '@/wap/wapPage/wapComponents/title/title.vue';
import buttonIcon from '@/wap/wapPage/wapComponents/title/buttonIcon.vue';
import { useProjectStore } from '@/store';
import { urls } from '@/utils/request/upload';
import { useRouter, useRoute } from 'vue-router';
import UnitImageNull from '@/components/unitImageNull/unitImageNull.vue';
const prefaceLeft = ref(null);
const prefaceRight = ref(null);
const props = defineProps({
  info: {
    type: Object,
  },
});
const htmlContent = ref('');
if (props.info.remarks) {
  let arr = props.info.remarks.split('\n');
  arr.forEach((el) => {
    if (el) {
      htmlContent.value =
        htmlContent.value +
        `<span>
${el}
</span>`;
    }
  });
}
const store = useProjectStore();
const router = useRouter();
const route = useRoute();
const clickPath = () => {
  store.setchildModel(props.info);
  store.setCurrent(0);
  // console.log(props.info);

  router.push({
    name: route.meta.loopType ? pathListLoop[8] : pathList[8],
    query: { childId: props.info.id },
  });
};
const animation2 = () => {
  const observer = new IntersectionObserver((entries) => {
    let canTrigger = true; // 标记是否可以触发
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码
        prefaceLeft.value.classList.add('animation-box2');
        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        // if (prefaceLeft.value) {
        //   prefaceLeft.value.classList.remove('animation-box2');
        // }
      }
    });
  });
  observer.observe(prefaceLeft.value);
};
const animation3 = () => {
  const observer = new IntersectionObserver((entries) => {
    let canTrigger = true; // 标记是否可以触发
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码
        prefaceRight.value.classList.add('animation-box3');
        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        prefaceRight.value.classList.remove('animation-box3');
      }
    });
  });
  observer.observe(prefaceRight.value);
};
onMounted(() => {
  animation2();
  animation3();
});
</script>

<style lang="less" scoped>
@import './index.less';
.left-btn {
  margin-top: 0px;
}
.preface-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.preface-content {
  display: flex;
  width: 100%;
  height: 100%;
  margin-top: 50px;
}
.preface-left {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 1;
  margin-left: 130px;
  margin-right: 130px;
  .left-title {
    text-align: left;
    text-indent: 2em;
    width: 100%;
    font-size: 16px;
    line-height: 28px;
    width: 100%;
    text-overflow: -o-ellipsis-lastline;
    overflow: hidden; //溢出内容隐藏
    text-overflow: ellipsis; //文本溢出部分用省略号表示
    display: -webkit-box; //特别显示模式
    -webkit-line-clamp: 6; //行数
    line-clamp: 6;
    line-height: 30px;
    -webkit-box-orient: vertical; //盒子中内容竖直排列
  }
}
.title {
  margin-bottom: 50px;
}
.preface-right {
  width: 37%;
  width: 380px;
  max-height: 710px;
  overflow: hidden;
  .preface-right-img {
    width: 100%;
    height: auto;
    max-height: 710px;
    transition: all 0.5s;
  }
}
.hw-wrap-spases {
  display: flex;
  flex-direction: column;
  :deep(span) {
    display: flex;
    text-indent: 2em;
  }
}
.preface-right:hover .preface-right-img {
  transform: scale(1.1);
}
</style>
